package aar.test.tessocr;

import android.content.Context;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.Toast;

import com.google.gson.Gson;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import aar.test.tessocr.adapter.CompanySearchInfoAdapter;
import aar.test.tessocr.adapter.MoneyListAdapter;
import aar.test.tessocr.baseApplication.BaseApplication;
import aar.test.tessocr.model.CompanySearchModel;
import aar.test.tessocr.model.DialogCallback;
import aar.test.tessocr.model.LzyResponse;
import aar.test.tessocr.model.MoneyListModel;
import aar.test.tessocr.model.loginModel;
import aar.test.tessocr.utils.ConstantPara;
import aar.test.tessocr.utils.PrefUtils;
import aar.test.tessocr.utils.Urls;
import clx.tessocr.ocreng.R;
import okgo.OkGo;
import okgo.model.Response;
import okhttp3.RequestBody;

import static aar.test.tessocr.Login1Activity.JSON;

public class CapitalDetailsActivity extends AppCompatActivity {

    private LinearLayout left_layout;

    private Context mContext;

//    private MoneyListAdapter moneyListAdapter;

    private ListView capital_details;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_capital_details);

        mContext = this;

        left_layout = findViewById(R.id.left_layout);
        left_layout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        capital_details=findViewById(R.id.capital_details);

        moneyList();
    }


    private List<MoneyListModel> mList;

    private void moneyList() {

        Map<String, Object> map = new HashMap<>();
        map.put("adminid", PrefUtils.getString(this, "userId", ""));

        Gson gg = new Gson();
        String json = gg.toJson(map);

        RequestBody body = RequestBody.create(JSON, json);
        OkGo.<LzyResponse<List<MoneyListModel>>>post(Urls.URL_MONEY_LIST)//
                .tag(this)//
                .upRequestBody(body)
                .isMultipart(false)         //强制使用 multipart/form-data 表单上传（只是演示，不需要的话不要设置。默认就是false）
                .execute(new DialogCallback<LzyResponse<List<MoneyListModel>>>(CapitalDetailsActivity.this) {
                    @Override
                    public void onSuccess(Response<LzyResponse<List<MoneyListModel>>> response) {


//
                        Log.e("MainActivity", "onSuccess111-----logout---------------");


                        if (null != response.body().data && response.body().data.size() > 0) {
                            mList = new ArrayList<>();
                            mList = response.body().data;
                            Log.e("MainActivity", "onSuccess-22----logout---------------" + response.body().data);
                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {

                                    MoneyListAdapter moneyListAdapter = new MoneyListAdapter(mContext,mList);

                                    capital_details.setAdapter(moneyListAdapter);
                                }
                            });
                        } else {


                        }


                    }

                    @Override
                    public void onError(Response<LzyResponse<List<MoneyListModel>>> response) {
                        Log.e("MainActivity", "onError---------------------");

                    }
                });


    }


}
